package com.leedsoft.spittr.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * Created by leeds on 2017/11/15.
 */
@Aspect
@Component
public class TestAop {
    @Pointcut("execution(* com.leedsoft.spittr.service.AopService.*(String,String)) && args(st,s2)")
    public void commonPointcut(String st, String s2) {

    }

    @Before("commonPointcut(s1,s2)")
    public void beforeLog(String s1, String s2) {
        System.out.println("这是传过来的参数：" + s1);
        System.out.println("这是传过来的参数：" + s2);
        System.out.println("beforeLog................");
    }
//    @Around("commonPointcut()")
    public Object testAfter(ProceedingJoinPoint joinPoint) {
        System.out.println("执行前");
        //获取连接点方法的参数
        System.out.println(joinPoint.getArgs().length > 0 ? joinPoint.getArgs()[0] : "没有参数");
        Object result = null;
        try {
            result = joinPoint.proceed();//执行连接点方法。同时获得返回值
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
        System.out.println("执行后");

        return "我改了你的返回值";//环绕通知的返回值，即最终的返回值
    }
}
